﻿using Entitas;
class PlayerSetDirectionSystem : IExecuteSystem
{
    PlayerContext playerContext;
    public PlayerSetDirectionSystem(Contexts contexts)
    {
        playerContext = contexts.player;
    }
    public void Execute()
    {
        if (playerContext.count == 1)
        {
            var player = playerContext.GetEntities().SingleEntity<PlayerEntity>();


            if (ServiceManager.InputService.UpKeyHeld&&!ServiceManager.InputService.DownKeyHeld)
            {
                player.ReplaceDirection(Direction.Up);
                
            }
             if (ServiceManager.InputService.DownKeyHeld&&!ServiceManager.InputService.UpKeyHeld)
            {
                player.ReplaceDirection(Direction.Down);
            }
             if (ServiceManager.InputService.LeftKeyHeld&&!ServiceManager.InputService.RightKeyHeld)
            {
                player.ReplaceDirection(Direction.Left);
            }
             if (ServiceManager.InputService.RightKeyHeld&&!ServiceManager.InputService.LeftKeyHeld)
            {
                player.ReplaceDirection(Direction.Right);
            }

            if (ServiceManager.InputService.UpKeyHeld && ServiceManager.InputService.RightKeyHeld)
            {
                player.ReplaceDirection(Direction.Up_Right);
            }
            if (ServiceManager.InputService.UpKeyHeld && ServiceManager.InputService.LeftKeyHeld)
            {
                player.ReplaceDirection(Direction.Up_Left);
            }
            if (ServiceManager.InputService.DownKeyHeld && ServiceManager.InputService.RightKeyHeld)
            {
                player.ReplaceDirection(Direction.Down_Right);
            }
            if (ServiceManager.InputService.DownKeyHeld && ServiceManager.InputService.LeftKeyHeld)
            {
                player.ReplaceDirection(Direction.Down_Left);
            }


        }
        // //released

            //if (ServiceManager.InputService.UPkeyReleased)
            //{
            //    if (player.direction.value == Direction.Up_Right)
            //        player.ReplaceDirection(Direction.Right);
            //    else if (player.direction.value == Direction.Up_Left)
            //        player.ReplaceDirection(Direction.Left);
            //    else player.ReplaceDirection(Direction.Up);
                   
            //}
            //if (ServiceManager.InputService.DownkeyReleased)
            //{
            //    if (player.direction.value == Direction.Down_Left)
            //        player.ReplaceDirection(Direction.Right);
            //    else if (player.direction.value == Direction.Up_Left)
            //        player.ReplaceDirection(Direction.Left);
            //    else player.ReplaceDirection(Direction.Up);

            //}
            //if (ServiceManager.InputService.UPkeyReleased)
            //{
            //    if (player.direction.value == Direction.Up_Right)
            //        player.ReplaceDirection(Direction.Right);
            //    else if (player.direction.value == Direction.Up_Left)
            //        player.ReplaceDirection(Direction.Left);
            //    else player.ReplaceDirection(Direction.Up);

            //}
            //if (ServiceManager.InputService.UPkeyReleased)
            //{
            //    if (player.direction.value == Direction.Up_Right)
            //        player.ReplaceDirection(Direction.Right);
            //    else if (player.direction.value == Direction.Up_Left)
            //        player.ReplaceDirection(Direction.Left);
            //    else player.ReplaceDirection(Direction.Up);

            //}
        }
}

